package jmine.tec.utils.collection;

/**
 * Utilitary class for performing fold operations
 * 
 * @author jrenaut
 */
public final class FoldUtils {

    /**
     */
    private FoldUtils() {
    }

    /**
     * @param <S> the return type
     * @param <T> the iterated type
     * @param iterable a {@link Iterable} of T
     * @param start a starting value of type S
     * @param operation a binary operation
     * @return the result of left-folding the given {@link Iterable} with the given operation
     */
    public static <S, T> S leftFold(Iterable<? extends T> iterable, S start, BinaryOperation<S, S, ? super T> operation) {
        S current = start;
        for (T t : iterable) {
            current = operation.apply(current, t);
        }
        return current;
    }

}
